{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import accuracy_score, confusion_matrix, classification_report, f1_score, recall_score, precision_score\n",
    "from sklearn.svm import SVC\n",
    "import joblib"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Cleaning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "             0           1             2         3         4         5  \\\n0     0.682996  0.77364117 -9.367768e-07  0.692656  0.729596 -0.174701   \n1     0.762095   0.7272415 -1.369458e-06  0.584345  0.742350 -0.059305   \n2     0.762095   0.7272415 -1.369458e-06  0.584345  0.742350 -0.059305   \n3     0.726126     0.69589 -1.350590e-06  0.546200  0.697156 -0.000828   \n4     0.726126     0.69589 -1.350590e-06  0.546200  0.697156 -0.000828   \n...        ...         ...           ...       ...       ...       ...   \n1796  0.768670  0.73333734 -7.503206e-07  0.643080  0.677789  0.003755   \n1797  0.756091   0.7364298 -7.255918e-07  0.630323  0.680481  0.004235   \n1798  0.751026  0.74793875 -8.269635e-07  0.618629  0.689210 -0.001354   \n1799  0.740190  0.76102793 -8.382949e-07  0.609556  0.705677  0.000564   \n1800  0.724711  0.75483525 -8.507028e-07  0.610402  0.708762  0.000557   \n\n             6         7         8         9  ...        54        55  \\\n0     0.691045  0.625183 -0.228506  0.649930  ...  0.507712  0.494957   \n1     0.438985  0.684447 -0.083520  0.375221  ...  0.589935  0.492781   \n2     0.438985  0.684447 -0.083520  0.375221  ...  0.589935  0.492781   \n3     0.419077  0.640116 -0.003470  0.368921  ...  0.622228  0.466040   \n4     0.419077  0.640116 -0.003470  0.368921  ...  0.622228  0.466040   \n...        ...       ...       ...       ...  ...       ...       ...   \n1796  0.578414  0.598121 -0.018650  0.525291  ...  0.569929  0.554485   \n1797  0.566116  0.601193 -0.018907  0.514663  ...  0.566694  0.557956   \n1798  0.550726  0.607424 -0.025242  0.500948  ...  0.571145  0.565462   \n1799  0.535308  0.624422 -0.022166  0.481659  ...  0.570382  0.576960   \n1800  0.535837  0.620425 -0.018407  0.481462  ...  0.587448  0.555102   \n\n            56        57        58        59        60        61        62  \\\n0    -0.017714  0.517896  0.548844 -0.029763  0.564395  0.574762 -0.016216   \n1    -0.009994  0.582887  0.531607 -0.003973  0.616653  0.555095 -0.000574   \n2    -0.009994  0.582887  0.531607 -0.003973  0.616653  0.555095 -0.000574   \n3     0.000354  0.615332  0.495862  0.020312  0.638481  0.523002  0.029026   \n4     0.000354  0.615332  0.495862  0.020312  0.638481  0.523002  0.029026   \n...        ...       ...       ...       ...       ...       ...       ...   \n1796 -0.099221  0.587647  0.612358 -0.087410  0.619529  0.620216 -0.075388   \n1797 -0.101260  0.585304  0.616279 -0.089827  0.618410  0.626375 -0.077260   \n1798 -0.105240  0.592090  0.622349 -0.095353  0.628224  0.626882 -0.083943   \n1799 -0.107344  0.593714  0.628928 -0.093116  0.631174  0.626211 -0.078013   \n1800 -0.101821  0.612868  0.607507 -0.087649  0.648860  0.597687 -0.071643   \n\n      Output  \n0        0.0  \n1        0.0  \n2        0.0  \n3        0.0  \n4        0.0  \n...      ...  \n1796     9.0  \n1797     9.0  \n1798     9.0  \n1799     9.0  \n1800     9.0  \n\n[1801 rows x 64 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n      <th>7</th>\n      <th>8</th>\n      <th>9</th>\n      <th>...</th>\n      <th>54</th>\n      <th>55</th>\n      <th>56</th>\n      <th>57</th>\n      <th>58</th>\n      <th>59</th>\n      <th>60</th>\n      <th>61</th>\n      <th>62</th>\n      <th>Output</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.682996</td>\n      <td>0.77364117</td>\n      <td>-9.367768e-07</td>\n      <td>0.692656</td>\n      <td>0.729596</td>\n      <td>-0.174701</td>\n      <td>0.691045</td>\n      <td>0.625183</td>\n      <td>-0.228506</td>\n      <td>0.649930</td>\n      <td>...</td>\n      <td>0.507712</td>\n      <td>0.494957</td>\n      <td>-0.017714</td>\n      <td>0.517896</td>\n      <td>0.548844</td>\n      <td>-0.029763</td>\n      <td>0.564395</td>\n      <td>0.574762</td>\n      <td>-0.016216</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.762095</td>\n      <td>0.7272415</td>\n      <td>-1.369458e-06</td>\n      <td>0.584345</td>\n      <td>0.742350</td>\n      <td>-0.059305</td>\n      <td>0.438985</td>\n      <td>0.684447</td>\n      <td>-0.083520</td>\n      <td>0.375221</td>\n      <td>...</td>\n      <td>0.589935</td>\n      <td>0.492781</td>\n      <td>-0.009994</td>\n      <td>0.582887</td>\n      <td>0.531607</td>\n      <td>-0.003973</td>\n      <td>0.616653</td>\n      <td>0.555095</td>\n      <td>-0.000574</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.762095</td>\n      <td>0.7272415</td>\n      <td>-1.369458e-06</td>\n      <td>0.584345</td>\n      <td>0.742350</td>\n      <td>-0.059305</td>\n      <td>0.438985</td>\n      <td>0.684447</td>\n      <td>-0.083520</td>\n      <td>0.375221</td>\n      <td>...</td>\n      <td>0.589935</td>\n      <td>0.492781</td>\n      <td>-0.009994</td>\n      <td>0.582887</td>\n      <td>0.531607</td>\n      <td>-0.003973</td>\n      <td>0.616653</td>\n      <td>0.555095</td>\n      <td>-0.000574</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.726126</td>\n      <td>0.69589</td>\n      <td>-1.350590e-06</td>\n      <td>0.546200</td>\n      <td>0.697156</td>\n      <td>-0.000828</td>\n      <td>0.419077</td>\n      <td>0.640116</td>\n      <td>-0.003470</td>\n      <td>0.368921</td>\n      <td>...</td>\n      <td>0.622228</td>\n      <td>0.466040</td>\n      <td>0.000354</td>\n      <td>0.615332</td>\n      <td>0.495862</td>\n      <td>0.020312</td>\n      <td>0.638481</td>\n      <td>0.523002</td>\n      <td>0.029026</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.726126</td>\n      <td>0.69589</td>\n      <td>-1.350590e-06</td>\n      <td>0.546200</td>\n      <td>0.697156</td>\n      <td>-0.000828</td>\n      <td>0.419077</td>\n      <td>0.640116</td>\n      <td>-0.003470</td>\n      <td>0.368921</td>\n      <td>...</td>\n      <td>0.622228</td>\n      <td>0.466040</td>\n      <td>0.000354</td>\n      <td>0.615332</td>\n      <td>0.495862</td>\n      <td>0.020312</td>\n      <td>0.638481</td>\n      <td>0.523002</td>\n      <td>0.029026</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1796</th>\n      <td>0.768670</td>\n      <td>0.73333734</td>\n      <td>-7.503206e-07</td>\n      <td>0.643080</td>\n      <td>0.677789</td>\n      <td>0.003755</td>\n      <td>0.578414</td>\n      <td>0.598121</td>\n      <td>-0.018650</td>\n      <td>0.525291</td>\n      <td>...</td>\n      <td>0.569929</td>\n      <td>0.554485</td>\n      <td>-0.099221</td>\n      <td>0.587647</td>\n      <td>0.612358</td>\n      <td>-0.087410</td>\n      <td>0.619529</td>\n      <td>0.620216</td>\n      <td>-0.075388</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1797</th>\n      <td>0.756091</td>\n      <td>0.7364298</td>\n      <td>-7.255918e-07</td>\n      <td>0.630323</td>\n      <td>0.680481</td>\n      <td>0.004235</td>\n      <td>0.566116</td>\n      <td>0.601193</td>\n      <td>-0.018907</td>\n      <td>0.514663</td>\n      <td>...</td>\n      <td>0.566694</td>\n      <td>0.557956</td>\n      <td>-0.101260</td>\n      <td>0.585304</td>\n      <td>0.616279</td>\n      <td>-0.089827</td>\n      <td>0.618410</td>\n      <td>0.626375</td>\n      <td>-0.077260</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1798</th>\n      <td>0.751026</td>\n      <td>0.74793875</td>\n      <td>-8.269635e-07</td>\n      <td>0.618629</td>\n      <td>0.689210</td>\n      <td>-0.001354</td>\n      <td>0.550726</td>\n      <td>0.607424</td>\n      <td>-0.025242</td>\n      <td>0.500948</td>\n      <td>...</td>\n      <td>0.571145</td>\n      <td>0.565462</td>\n      <td>-0.105240</td>\n      <td>0.592090</td>\n      <td>0.622349</td>\n      <td>-0.095353</td>\n      <td>0.628224</td>\n      <td>0.626882</td>\n      <td>-0.083943</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1799</th>\n      <td>0.740190</td>\n      <td>0.76102793</td>\n      <td>-8.382949e-07</td>\n      <td>0.609556</td>\n      <td>0.705677</td>\n      <td>0.000564</td>\n      <td>0.535308</td>\n      <td>0.624422</td>\n      <td>-0.022166</td>\n      <td>0.481659</td>\n      <td>...</td>\n      <td>0.570382</td>\n      <td>0.576960</td>\n      <td>-0.107344</td>\n      <td>0.593714</td>\n      <td>0.628928</td>\n      <td>-0.093116</td>\n      <td>0.631174</td>\n      <td>0.626211</td>\n      <td>-0.078013</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1800</th>\n      <td>0.724711</td>\n      <td>0.75483525</td>\n      <td>-8.507028e-07</td>\n      <td>0.610402</td>\n      <td>0.708762</td>\n      <td>0.000557</td>\n      <td>0.535837</td>\n      <td>0.620425</td>\n      <td>-0.018407</td>\n      <td>0.481462</td>\n      <td>...</td>\n      <td>0.587448</td>\n      <td>0.555102</td>\n      <td>-0.101821</td>\n      <td>0.612868</td>\n      <td>0.607507</td>\n      <td>-0.087649</td>\n      <td>0.648860</td>\n      <td>0.597687</td>\n      <td>-0.071643</td>\n      <td>9.0</td>\n    </tr>\n  </tbody>\n</table>\n<p>1801 rows × 64 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../dataSet/final_datasetBSL.csv')\n",
    "df.columns = [i for i in range(df.shape[1])]\n",
    "df = df.rename(columns={63: 'Output'})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Uncleaned dataset shape = (1801, 64)\n"
     ]
    }
   ],
   "source": [
    "print(\"Uncleaned dataset shape =\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of null values = 0\n"
     ]
    }
   ],
   "source": [
    "# removing null values from our dataset\n",
    "\n",
    "all_null_values = df[df.iloc[:, 0] == 0]\n",
    "print(\"Number of null values =\", len(all_null_values.index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dropping those null values from our dataset\n",
    "\n",
    "df.drop(all_null_values.index, inplace=True)\n",
    "df = df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "             0           1             2         3         4         5  \\\n0     0.682996  0.77364117 -9.367768e-07  0.692656  0.729596 -0.174701   \n1     0.762095   0.7272415 -1.369458e-06  0.584345  0.742350 -0.059305   \n2     0.762095   0.7272415 -1.369458e-06  0.584345  0.742350 -0.059305   \n3     0.726126     0.69589 -1.350590e-06  0.546200  0.697156 -0.000828   \n4     0.726126     0.69589 -1.350590e-06  0.546200  0.697156 -0.000828   \n...        ...         ...           ...       ...       ...       ...   \n1796  0.768670  0.73333734 -7.503206e-07  0.643080  0.677789  0.003755   \n1797  0.756091   0.7364298 -7.255918e-07  0.630323  0.680481  0.004235   \n1798  0.751026  0.74793875 -8.269635e-07  0.618629  0.689210 -0.001354   \n1799  0.740190  0.76102793 -8.382949e-07  0.609556  0.705677  0.000564   \n1800  0.724711  0.75483525 -8.507028e-07  0.610402  0.708762  0.000557   \n\n             6         7         8         9  ...        54        55  \\\n0     0.691045  0.625183 -0.228506  0.649930  ...  0.507712  0.494957   \n1     0.438985  0.684447 -0.083520  0.375221  ...  0.589935  0.492781   \n2     0.438985  0.684447 -0.083520  0.375221  ...  0.589935  0.492781   \n3     0.419077  0.640116 -0.003470  0.368921  ...  0.622228  0.466040   \n4     0.419077  0.640116 -0.003470  0.368921  ...  0.622228  0.466040   \n...        ...       ...       ...       ...  ...       ...       ...   \n1796  0.578414  0.598121 -0.018650  0.525291  ...  0.569929  0.554485   \n1797  0.566116  0.601193 -0.018907  0.514663  ...  0.566694  0.557956   \n1798  0.550726  0.607424 -0.025242  0.500948  ...  0.571145  0.565462   \n1799  0.535308  0.624422 -0.022166  0.481659  ...  0.570382  0.576960   \n1800  0.535837  0.620425 -0.018407  0.481462  ...  0.587448  0.555102   \n\n            56        57        58        59        60        61        62  \\\n0    -0.017714  0.517896  0.548844 -0.029763  0.564395  0.574762 -0.016216   \n1    -0.009994  0.582887  0.531607 -0.003973  0.616653  0.555095 -0.000574   \n2    -0.009994  0.582887  0.531607 -0.003973  0.616653  0.555095 -0.000574   \n3     0.000354  0.615332  0.495862  0.020312  0.638481  0.523002  0.029026   \n4     0.000354  0.615332  0.495862  0.020312  0.638481  0.523002  0.029026   \n...        ...       ...       ...       ...       ...       ...       ...   \n1796 -0.099221  0.587647  0.612358 -0.087410  0.619529  0.620216 -0.075388   \n1797 -0.101260  0.585304  0.616279 -0.089827  0.618410  0.626375 -0.077260   \n1798 -0.105240  0.592090  0.622349 -0.095353  0.628224  0.626882 -0.083943   \n1799 -0.107344  0.593714  0.628928 -0.093116  0.631174  0.626211 -0.078013   \n1800 -0.101821  0.612868  0.607507 -0.087649  0.648860  0.597687 -0.071643   \n\n      Output  \n0        0.0  \n1        0.0  \n2        0.0  \n3        0.0  \n4        0.0  \n...      ...  \n1796     9.0  \n1797     9.0  \n1798     9.0  \n1799     9.0  \n1800     9.0  \n\n[1543 rows x 64 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n      <th>3</th>\n      <th>4</th>\n      <th>5</th>\n      <th>6</th>\n      <th>7</th>\n      <th>8</th>\n      <th>9</th>\n      <th>...</th>\n      <th>54</th>\n      <th>55</th>\n      <th>56</th>\n      <th>57</th>\n      <th>58</th>\n      <th>59</th>\n      <th>60</th>\n      <th>61</th>\n      <th>62</th>\n      <th>Output</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.682996</td>\n      <td>0.77364117</td>\n      <td>-9.367768e-07</td>\n      <td>0.692656</td>\n      <td>0.729596</td>\n      <td>-0.174701</td>\n      <td>0.691045</td>\n      <td>0.625183</td>\n      <td>-0.228506</td>\n      <td>0.649930</td>\n      <td>...</td>\n      <td>0.507712</td>\n      <td>0.494957</td>\n      <td>-0.017714</td>\n      <td>0.517896</td>\n      <td>0.548844</td>\n      <td>-0.029763</td>\n      <td>0.564395</td>\n      <td>0.574762</td>\n      <td>-0.016216</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.762095</td>\n      <td>0.7272415</td>\n      <td>-1.369458e-06</td>\n      <td>0.584345</td>\n      <td>0.742350</td>\n      <td>-0.059305</td>\n      <td>0.438985</td>\n      <td>0.684447</td>\n      <td>-0.083520</td>\n      <td>0.375221</td>\n      <td>...</td>\n      <td>0.589935</td>\n      <td>0.492781</td>\n      <td>-0.009994</td>\n      <td>0.582887</td>\n      <td>0.531607</td>\n      <td>-0.003973</td>\n      <td>0.616653</td>\n      <td>0.555095</td>\n      <td>-0.000574</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.762095</td>\n      <td>0.7272415</td>\n      <td>-1.369458e-06</td>\n      <td>0.584345</td>\n      <td>0.742350</td>\n      <td>-0.059305</td>\n      <td>0.438985</td>\n      <td>0.684447</td>\n      <td>-0.083520</td>\n      <td>0.375221</td>\n      <td>...</td>\n      <td>0.589935</td>\n      <td>0.492781</td>\n      <td>-0.009994</td>\n      <td>0.582887</td>\n      <td>0.531607</td>\n      <td>-0.003973</td>\n      <td>0.616653</td>\n      <td>0.555095</td>\n      <td>-0.000574</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.726126</td>\n      <td>0.69589</td>\n      <td>-1.350590e-06</td>\n      <td>0.546200</td>\n      <td>0.697156</td>\n      <td>-0.000828</td>\n      <td>0.419077</td>\n      <td>0.640116</td>\n      <td>-0.003470</td>\n      <td>0.368921</td>\n      <td>...</td>\n      <td>0.622228</td>\n      <td>0.466040</td>\n      <td>0.000354</td>\n      <td>0.615332</td>\n      <td>0.495862</td>\n      <td>0.020312</td>\n      <td>0.638481</td>\n      <td>0.523002</td>\n      <td>0.029026</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.726126</td>\n      <td>0.69589</td>\n      <td>-1.350590e-06</td>\n      <td>0.546200</td>\n      <td>0.697156</td>\n      <td>-0.000828</td>\n      <td>0.419077</td>\n      <td>0.640116</td>\n      <td>-0.003470</td>\n      <td>0.368921</td>\n      <td>...</td>\n      <td>0.622228</td>\n      <td>0.466040</td>\n      <td>0.000354</td>\n      <td>0.615332</td>\n      <td>0.495862</td>\n      <td>0.020312</td>\n      <td>0.638481</td>\n      <td>0.523002</td>\n      <td>0.029026</td>\n      <td>0.0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1796</th>\n      <td>0.768670</td>\n      <td>0.73333734</td>\n      <td>-7.503206e-07</td>\n      <td>0.643080</td>\n      <td>0.677789</td>\n      <td>0.003755</td>\n      <td>0.578414</td>\n      <td>0.598121</td>\n      <td>-0.018650</td>\n      <td>0.525291</td>\n      <td>...</td>\n      <td>0.569929</td>\n      <td>0.554485</td>\n      <td>-0.099221</td>\n      <td>0.587647</td>\n      <td>0.612358</td>\n      <td>-0.087410</td>\n      <td>0.619529</td>\n      <td>0.620216</td>\n      <td>-0.075388</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1797</th>\n      <td>0.756091</td>\n      <td>0.7364298</td>\n      <td>-7.255918e-07</td>\n      <td>0.630323</td>\n      <td>0.680481</td>\n      <td>0.004235</td>\n      <td>0.566116</td>\n      <td>0.601193</td>\n      <td>-0.018907</td>\n      <td>0.514663</td>\n      <td>...</td>\n      <td>0.566694</td>\n      <td>0.557956</td>\n      <td>-0.101260</td>\n      <td>0.585304</td>\n      <td>0.616279</td>\n      <td>-0.089827</td>\n      <td>0.618410</td>\n      <td>0.626375</td>\n      <td>-0.077260</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1798</th>\n      <td>0.751026</td>\n      <td>0.74793875</td>\n      <td>-8.269635e-07</td>\n      <td>0.618629</td>\n      <td>0.689210</td>\n      <td>-0.001354</td>\n      <td>0.550726</td>\n      <td>0.607424</td>\n      <td>-0.025242</td>\n      <td>0.500948</td>\n      <td>...</td>\n      <td>0.571145</td>\n      <td>0.565462</td>\n      <td>-0.105240</td>\n      <td>0.592090</td>\n      <td>0.622349</td>\n      <td>-0.095353</td>\n      <td>0.628224</td>\n      <td>0.626882</td>\n      <td>-0.083943</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1799</th>\n      <td>0.740190</td>\n      <td>0.76102793</td>\n      <td>-8.382949e-07</td>\n      <td>0.609556</td>\n      <td>0.705677</td>\n      <td>0.000564</td>\n      <td>0.535308</td>\n      <td>0.624422</td>\n      <td>-0.022166</td>\n      <td>0.481659</td>\n      <td>...</td>\n      <td>0.570382</td>\n      <td>0.576960</td>\n      <td>-0.107344</td>\n      <td>0.593714</td>\n      <td>0.628928</td>\n      <td>-0.093116</td>\n      <td>0.631174</td>\n      <td>0.626211</td>\n      <td>-0.078013</td>\n      <td>9.0</td>\n    </tr>\n    <tr>\n      <th>1800</th>\n      <td>0.724711</td>\n      <td>0.75483525</td>\n      <td>-8.507028e-07</td>\n      <td>0.610402</td>\n      <td>0.708762</td>\n      <td>0.000557</td>\n      <td>0.535837</td>\n      <td>0.620425</td>\n      <td>-0.018407</td>\n      <td>0.481462</td>\n      <td>...</td>\n      <td>0.587448</td>\n      <td>0.555102</td>\n      <td>-0.101821</td>\n      <td>0.612868</td>\n      <td>0.607507</td>\n      <td>-0.087649</td>\n      <td>0.648860</td>\n      <td>0.597687</td>\n      <td>-0.071643</td>\n      <td>9.0</td>\n    </tr>\n  </tbody>\n</table>\n<p>1543 rows × 64 columns</p>\n</div>"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cleaned dataset shape = (1543, 64)\n"
     ]
    }
   ],
   "source": [
    "print(\"Cleaned dataset shape =\", df.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Preparation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Features shape = (1543, 63)\n",
      "Labels shape = (1543,)\n"
     ]
    }
   ],
   "source": [
    "X = df.iloc[:, :-1]\n",
    "print(\"Features shape =\", X.shape)\n",
    "\n",
    "Y = df.iloc[:, -1]\n",
    "print(\"Labels shape =\", Y.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Model Making"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "svm = SVC(C=100, gamma=0.5, kernel='rbf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "SVC(C=100, gamma=0.5)",
      "text/html": "<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVC(C=100, gamma=0.5)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SVC</label><div class=\"sk-toggleable__content\"><pre>SVC(C=100, gamma=0.5)</pre></div></div></div></div></div>"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "svm.fit(x_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training score = 1.0\n"
     ]
    }
   ],
   "source": [
    "print(\"Training score =\", svm.score(x_train, y_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "['../model/model.pkl']"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(svm, \"../model/model.pkl\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred = svm.predict(x_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Testing score = 0.9935275080906149\n"
     ]
    }
   ],
   "source": [
    "print(\"Testing score =\", accuracy_score(y_test, y_pred))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "cf_matrix = confusion_matrix(y_test, y_pred)\n",
    "f1 = f1_score(y_test, y_pred, average='micro')\n",
    "recall = recall_score(y_test, y_pred, average='micro')\n",
    "precision = precision_score(y_test, y_pred, average='micro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "(0.9935275080906149, 0.9935275080906149, 0.9935275080906149)"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f1, recall, precision"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}